/*
 * Copyright (C) 2019 Baidu, Inc. All Rights Reserved.
 */
package com.bootdo.hjh.dao.provider;

import java.util.Map;

import org.apache.ibatis.annotations.Param;

public class TihuoOrderProvider {

    public String listTihuoOrders(Map<String, Object> map) {
        Integer offset = (Integer) map.get("offset");
        Integer limit = (Integer) map.get("limit");
        Integer productId = (Integer) map.get("productId");
        Long userId = (Long) map.get("userId");
        StringBuilder sb = new StringBuilder();
        sb.append("select * from t_tihuo_order where 1>0 ");
        if (productId != null && productId > 0) {
            sb.append(" and product_id = #{productId}");
        }
        if (userId != null) {
            sb.append(" and user_id = #{userId}");
        }
        sb.append(" order by id desc");
        if (offset != null && limit != null) {
            sb.append(" limit #{offset},#{limit}");
        }
        return sb.toString();
    }

    public String countTihuoOrder(Map<String, Object> map) {
        Integer productId = (Integer) map.get("productId");
        Long userId = (Long) map.get("userId");
        StringBuilder sb = new StringBuilder();
        sb.append("select count(1) from t_tihuo_order where 1>0 ");
        if (productId != null && productId > 0) {
            sb.append(" and product_id = #{productId}");
        }
        if (userId != null) {
            sb.append(" and user_id = #{userId}");
        }
        return sb.toString();
    }

    public String updateFahuo(Map<String, Object> map) {
        Integer status =(Integer) map.get("status");
        Integer shippingChannel =(Integer) map.get("shippingChannel");
        String shippingSn =(String) map.get("shippingSn");
        StringBuilder sb = new StringBuilder();
        sb.append("update t_tihuo_order set id = id ");
        if (status!=null && status > 0) {
            sb.append(", status = #{status}");
        }
        if (shippingChannel!=null && shippingChannel > 0) {
            sb.append(", shipping_channel = #{shippingChannel}");
        }
        if (shippingSn!=null) {
            sb.append(", shipping_sn = #{shippingSn}");
        }

        sb.append(" where id = #{id} ");
        return sb.toString();
    }
}
